import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:jetour_line/base_widget/base_image.dart';
import 'package:jetour_line/utils/aha_utils.dart';
import 'package:jetour_line/utils/extension_int.dart';
import 'package:shared_preferences/shared_preferences.dart';

class GuideViewWidget extends StatefulWidget {
  const GuideViewWidget({super.key});

  @override
  State<GuideViewWidget> createState() => _GuideViewWidgetState();
}

class _GuideViewWidgetState extends State<GuideViewWidget> {
  bool isFirst = false;
  bool showFirst = true;
  bool showSecond = false;
  String firstKey = 'first_time1';
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    checkFirstTime();
  }
  SharedPreferences? prefs;
  void checkFirstTime() async {
    prefs = await SharedPreferences.getInstance();
    bool isFirstTime = prefs!.getBool(firstKey) ?? true;
    if (isFirstTime) {
      setState(() {
        isFirst = true;
      });

    } else {
    }
  }
  @override
  Widget build(BuildContext context) {
    return !isFirst
        ? SizedBox()
        : Stack(
            children: [
              Opacity(
                opacity: 0.7,
                child: Container(
                  color: Colors.black,
                  height: double.infinity,
                  width: double.infinity,
                ),
              ),
              if (showFirst)
                Positioned(
                    top: AhaUtils.getAppBarHeight(context) + 16.px,
                    right: 0,
                    child: GestureDetector(
                        onTap: () {
                          setState(() {
                            showFirst = false;
                            showSecond = true;
                          });

                        },
                        child: BaseImage(
                          image: 'img_xstj_02',
                          width: 524.px,
                        ))),

              if (showSecond)
                Positioned(
                    bottom: 0,
                    left: 106.px,
                    right: 106.px,
                    child: GestureDetector(
                        onTap: () {
                          setState(() {
                            isFirst = false;
                          });
                          prefs!.setBool(firstKey, false);
                        },
                        child: const BaseImage(
                          image: 'img_xstj_01',
                        ))),
            ],
          );
  }
}
